

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Appendix: wrapping Fortran 90 Code &mdash; quippy 7ea04c5+ documentation</title>
  

  
  
    <link rel="shortcut icon" href="_static/favicon.ico"/>
  
  
  

  
  <script type="text/javascript" src="_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script type="text/javascript" src="_static/jquery.js"></script>
        <script type="text/javascript" src="_static/underscore.js"></script>
        <script type="text/javascript" src="_static/doctools.js"></script>
        <script type="text/javascript" src="_static/language_data.js"></script>
        <script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
        <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"processClass": "math|output_area", "processEscapes": true, "ignoreClass": "document", "inlineMath": [["$", "$"], ["\\(", "\\)"]]}})</script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/theme_overrides.css" type="text/css" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="f90doc — Fortran 90 source code scanner" href="f90doc.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="index.html" class="icon icon-home"> quippy
          

          
            
            <img src="_static/hybrid.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
              <div class="version">
                7ea04c5+
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
    
            
            
              
            
            
              <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="intro.html">Introduction to <code class="docutils literal notranslate"><span class="pre">quippy</span></code></a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation of QUIP and quippy</a></li>
<li class="toctree-l1"><a class="reference internal" href="Tutorials/index.html">Tutorials</a></li>
<li class="toctree-l1"><a class="reference internal" href="quippy.html">Quippy library reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="visualisation.html">Visualisation Tools</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Appendix: wrapping Fortran 90 Code</a><ul>
<li class="toctree-l2"><a class="reference internal" href="f90doc.html"><code class="docutils literal notranslate"><span class="pre">f90doc</span></code> — Fortran 90 source code scanner</a></li>
<li class="toctree-l2"><a class="reference internal" href="f2py_wrapper_gen.html"><code class="docutils literal notranslate"><span class="pre">f2py_wrapper_gen</span></code> — Fortran 90 source code wrapping</a></li>
<li class="toctree-l2"><a class="reference internal" href="patch_f2py.html"><code class="docutils literal notranslate"><span class="pre">patch_f2py</span></code> — modify <code class="docutils literal notranslate"><span class="pre">numpy.f2py</span></code> at runtime</a></li>
<li class="toctree-l2"><a class="reference internal" href="oo_fortran.html">Fortran 90 derived-type support</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="teach_sparse.html">Command line options of the teach_sparse main program</a></li>
</ul>

            
          
    <p></p>
    <ul>
        <li><a href="genindex.html">Index</a></li>
        <li><a href="py-modindex.html">Module Index</a></li>
        <li><a href="search.html">Search Page</a></li>
        <li><a href="_modules/index.html">Module Source Code</a></li>
    </ul>
  
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">quippy</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>Appendix: wrapping Fortran 90 Code</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/fortran_wrapper.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  
<style>
/* CSS overrides for sphinx_rtd_theme */

/* 24px margin */
.nbinput.nblast,
.nboutput.nblast {
    margin-bottom: 19px;  /* padding has already 5px */
}

/* ... except between code cells! */
.nblast + .nbinput {
    margin-top: -19px;
}

.admonition > p:before {
    margin-right: 4px;  /* make room for the exclamation icon */
}

/* Fix math alignment, see https://github.com/rtfd/sphinx_rtd_theme/pull/686 */
.math {
    text-align: unset;
}
</style>
<div class="section" id="appendix-wrapping-fortran-90-code">
<span id="wrapping-fortran-90-code"></span><h1>Appendix: wrapping Fortran 90 Code<a class="headerlink" href="#appendix-wrapping-fortran-90-code" title="Permalink to this headline">¶</a></h1>
<p>This section describes the machinery involved in connecting between
Python and Fortran. You should only read it if you want to extend
or modify quippy, or if you’re interested in how it works.</p>
<p>There are four steps in the process of wrapping a QUIP Fortran
routine to allow it to be called from quippy. The first two take place
at compile-time (and so these modules do not form part of the
installed quippy package), and the last two at run-time.</p>
<ol class="arabic simple">
<li><a class="reference internal" href="f90doc.html#module-f90doc" title="f90doc: Read Fortan 90 sources and extract documenataion strings"><code class="xref py py-mod docutils literal notranslate"><span class="pre">f90doc</span></code></a> is used to scan the Fortran source file,
building up a data struture which describes all the types, subroutines
and functions found in the file.</li>
<li><a class="reference internal" href="f2py_wrapper_gen.html#module-f2py_wrapper_gen" title="f2py_wrapper_gen: Generate simplified Fortran 90 source suitable for f2py"><code class="xref py py-mod docutils literal notranslate"><span class="pre">f2py_wrapper_gen</span></code></a> is used to write a simplified Fortran 90
prototype for each routine, with derived type arguments replaced by
integer arrays containing a representation of a pointer to the
derived type, in the manner described in <a class="reference internal" href="intro.html#pletzer2008" id="id1">[Pletzer2008]</a> This allows
us to pass opaque references to the true Fortran derived type data
structures back and forth between Python and Fortran. The
<code class="xref py py-mod docutils literal notranslate"><span class="pre">patch_f2py</span></code> module is used to patch the <a class="reference external" href="https://docs.scipy.org/doc/numpy/f2py/usage.html#module-numpy.f2py" title="(in NumPy v1.16)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">numpy.f2py</span></code></a>
system at runtime, to slightly modify the way it generates C code.</li>
<li><a class="reference internal" href="oo_fortran.html#module-quippy.oo_fortran" title="quippy.oo_fortran: Fortran 90 derived-type support"><code class="xref py py-mod docutils literal notranslate"><span class="pre">quippy.oo_fortran</span></code></a> acts as a thin object-oriented layer on
top of the f2py generated wrapper functions which handles
conversion between Python object instances and Fortran derived-type
variables, converting arguments back and forth automatically.</li>
</ol>
<p>Contents:</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="f90doc.html"><code class="docutils literal notranslate"><span class="pre">f90doc</span></code> — Fortran 90 source code scanner</a><ul>
<li class="toctree-l2"><a class="reference internal" href="f90doc.html#command-line-usage">Command line usage</a></li>
<li class="toctree-l2"><a class="reference internal" href="f90doc.html#module-usage">Module usage</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="f2py_wrapper_gen.html"><code class="docutils literal notranslate"><span class="pre">f2py_wrapper_gen</span></code> — Fortran 90 source code wrapping</a></li>
<li class="toctree-l1"><a class="reference internal" href="patch_f2py.html"><code class="docutils literal notranslate"><span class="pre">patch_f2py</span></code> — modify <code class="docutils literal notranslate"><span class="pre">numpy.f2py</span></code> at runtime</a></li>
<li class="toctree-l1"><a class="reference internal" href="oo_fortran.html">Fortran 90 derived-type support</a><ul class="simple">
</ul>
</li>
</ul>
</div>
<p>References:</p>
<table class="docutils citation" frame="void" id="pletzer2008" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[Pletzer2008]</a></td><td>Pletzer, A et al., Exposing Fortran Derived Types to C and Other Languages,
<em>Computing in Science and Engineering</em>, <strong>10</strong>, 86 (2008).
<a class="reference external" href="http://link.aip.org/link/?CSENFA/10/86/1">http://link.aip.org/link/?CSENFA/10/86/1</a></td></tr>
</tbody>
</table>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="f90doc.html" class="btn btn-neutral float-right" title="f90doc — Fortran 90 source code scanner" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2008-2016, James Kermode

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>